package com.itheima.test0910.test01;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class LocalDateTimeTest01 {
    public static void main(String[] args) {
        //LocalDateTime转换成字符串对象
        LocalDateTime now = LocalDateTime.now();
        System.out.println("当前时间" + now);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = now.format(formatter);
        System.out.println("转换成字符串后" + format);


        //把字符串对象转换成LocalDateTime对象
        String s = format;
        DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = LocalDateTime.parse(s,formatter1);
        System.out.println("转换成LocalDateTime对象" + localDateTime);
    }
}
